-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Handle uninitialised helpers better #767
Conversation
Size Change: +6.38 kB (+1%) Total Size: 684 kB
ℹ️ View Unchanged
|
# Conflicts: # src/posthog-core.ts
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
# Conflicts: # src/posthog-core.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clicked around locally and got events 👍
Changes
Currently if you call posthog methods before the
init
method is called, you get a lot of potential errors largely because we forcefully set the type to be defined.A typical case for this is where you only intialise PostHog if in a production environment.
This makes the lazy options truly lazy, with some early exits and otherwise optional accessors to ensure we don't call things that would crash.
I think we need a much more concrete solution for this (maybe having a decorator type approach to make sure no method runs without the lazy loaded values existing (i.e. init being called)) but for now this should at least stop people's browsers from crashing.
Checklist